home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume10 / ptoc / part06 < prev    next >
Encoding:
Internet Message Format  |  1987-07-27  |  40.2 KB

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i070:  Pascal to C translator, Part06/12
  5. Message-ID: <721@uunet.UU.NET>
  6. Date: 28 Jul 87 19:35:48 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 1547
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: Per Bergsten <mcvax!enea!chalmers!holtec!perb>
  12. Posting-number: Volume 10, Issue 70
  13. Archive-name: ptoc/Part06
  14.  
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 6 (of 12)."
  23. # Contents:  ptc.c.4
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'ptc.c.4' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'ptc.c.4'\"
  27. else
  28. echo shar: Extracting \"'ptc.c.4'\" \(37883 characters\)
  29. sed "s/^X//" >'ptc.c.4' <<'END_OF_FILE'
  30. X        renamp(tp->U.V13.tsubsub, true);
  31. X        if (on && (tp->U.V13.tsubstmt != (struct S61 *)NIL)) {
  32. X            sp = tp->U.V13.tsubid->U.V43.tsym;
  33. X            if (sp->U.V6.lid->inref > 1) {
  34. X                sp->U.V6.lid = mkrename('P', sp->U.V6.lid);
  35. X                sp->U.V6.lid->inref = sp->U.V6.lid->inref - 1;
  36. X            }
  37. X        }
  38. X        tp = tp->tnext;
  39. X    }
  40. X}
  41. X
  42. Xvoid initcode();
  43. X
  44. X boolean
  45. Xfilevar(tp)
  46. X    treeptr    tp;
  47. X{
  48. X    register boolean    R168;
  49. X    boolean    fv;
  50. X    treeptr    tq;
  51. X
  52. X    switch (tp->tt) {
  53. X      case npredef:
  54. X        fv = (boolean)(tp == typnods.A[(int)(ttext)]);
  55. X        break ;
  56. X      case nfileof:
  57. X        fv = true;
  58. X        break ;
  59. X      case nconfarr:
  60. X        fv = filevar(typeof(tp->U.V22.tcelem));
  61. X        break ;
  62. X      case narray:
  63. X        fv = filevar(typeof(tp->U.V23.taelem));
  64. X        break ;
  65. X      case nrecord:
  66. X        fv = false;
  67. X        tq = tp->U.V21.tvlist;
  68. X        while (tq != (struct S61 *)NIL) {
  69. X            if (filevar(tq->U.V20.tvrnt))
  70. X                error(evrntfile);
  71. X            tq = tq->tnext;
  72. X        }
  73. X        tq = tp->U.V21.tflist;
  74. X        while (tq != (struct S61 *)NIL) {
  75. X            if (filevar(typeof(tq->U.V14.tbind))) {
  76. X                fv = true;
  77. X                tq = (struct S61 *)NIL;
  78. X            } else
  79. X                tq = tq->tnext;
  80. X        }
  81. X        break ;
  82. X      case nptr:
  83. X        fv = false;
  84. X        if (!tp->U.V16.tptrflag) {
  85. X            tp->U.V16.tptrflag = true;
  86. X            if (filevar(typeof(tp->U.V16.tptrid)))
  87. X                error(evarfile);
  88. X            tp->U.V16.tptrflag = false;
  89. X        }
  90. X        break ;
  91. X      case nsubrange:  case nscalar:  case nsetof:
  92. X        fv = false;
  93. X        break ;
  94. X      default:
  95. X        Caseerror(Line);
  96. X    }
  97. X    R168 = fv;
  98. X    return R168;
  99. X}
  100. X
  101. X treeptr
  102. Xfileinit(ti, tq, opn)
  103. X    treeptr    ti, tq;
  104. X    boolean    opn;
  105. X{
  106. X    register treeptr    R169;
  107. X    treeptr    tx, ty, tz;
  108. X
  109. X    switch (tq->tt) {
  110. X      case narray:
  111. X        tz = newid(mkvariable('I'));
  112. X        ty = mknode(nvar);
  113. X        ty->U.V14.tattr = aregister;
  114. X        ty->U.V14.tidl = tz;
  115. X        ty->U.V14.tbind = typeof(tq->U.V23.taindx);
  116. X        tz = tq;
  117. X        while (!(Member((unsigned)(tz->tt), Conset[137])))
  118. X            tz = tz->tup;
  119. X        linkup(tz, ty);
  120. X        if (tz->U.V13.tsubvar == (struct S61 *)NIL)
  121. X            tz->U.V13.tsubvar = ty;
  122. X        else {
  123. X            tz = tz->U.V13.tsubvar;
  124. X            while (tz->tnext != (struct S61 *)NIL)
  125. X                tz = tz->tnext;
  126. X            tz->tnext = ty;
  127. X        }
  128. X        ty = ty->U.V14.tidl;
  129. X        tz = mknode(nindex);
  130. X        tz->U.V39.tvariable = ti;
  131. X        tz->U.V39.toffset = ty;
  132. X        tz = fileinit(tz, tq->U.V23.taelem, opn);
  133. X        tx = mknode(nfor);
  134. X        tx->U.V34.tforid = ty;
  135. X        ty = typeof(tq->U.V23.taindx);
  136. X        if (ty->tt == nsubrange) {
  137. X            tx->U.V34.tfrom = ty->U.V19.tlo;
  138. X            tx->U.V34.tto = ty->U.V19.thi;
  139. X        } else
  140. X            if (ty->tt == nscalar) {
  141. X                ty = ty->U.V17.tscalid;
  142. X                tx->U.V34.tfrom = ty;
  143. X                while (ty->tnext != (struct S61 *)NIL)
  144. X                    ty = ty->tnext;
  145. X                tx->U.V34.tto = ty;
  146. X            } else
  147. X                if (ty == typnods.A[(int)(tchar)]) {
  148. X                    currsym.st = schar;
  149. X                    currsym.U.V2.vchr = minchar;
  150. X                    tx->U.V34.tfrom = mklit();
  151. X                    currsym.st = schar;
  152. X                    currsym.U.V2.vchr = maxchar;
  153. X                    tx->U.V34.tto = mklit();
  154. X                } else
  155. X                    if (ty == typnods.A[(int)(tinteger)]) {
  156. X                        currsym.st = sinteger;
  157. X                        currsym.U.V3.vint = -maxint;
  158. X                        tx->U.V34.tfrom = mklit();
  159. X                        currsym.st = sinteger;
  160. X                        currsym.U.V3.vint = maxint;
  161. X                        tx->U.V34.tto = mklit();
  162. X                    } else
  163. X                        fatal(etree);
  164. X        tx->U.V34.tforstmt = tz;
  165. X        tx->U.V34.tincr = true;
  166. X        break ;
  167. X      case npredef:  case nfileof:
  168. X        if (opn) {
  169. X            ty = mknode(nselect);
  170. X            ty->U.V40.trecord = ti;
  171. X            ty->U.V40.tfield = oldid(defnams.A[(int)(dzinit)]->U.V6.lid, lforward);
  172. X            tx = mknode(nassign);
  173. X            tx->U.V27.tlhs = ty;
  174. X            currsym.st = sinteger;
  175. X            currsym.U.V3.vint = 0;
  176. X            tx->U.V27.trhs = mklit();
  177. X        } else {
  178. X            tx = mknode(ncall);
  179. X            tx->U.V30.tcall = oldid(defnams.A[(int)(dclose)]->U.V6.lid, lidentifier);
  180. X            tx->U.V30.taparm = ti;
  181. X        }
  182. X        break ;
  183. X      case nrecord:
  184. X        ty = (struct S61 *)NIL;
  185. X        tq = tq->U.V21.tflist;
  186. X        while (tq != (struct S61 *)NIL) {
  187. X            if (filevar(typeof(tq->U.V14.tbind))) {
  188. X                tz = tq->U.V14.tidl;
  189. X                while (tz != (struct S61 *)NIL) {
  190. X                    tx = mknode(nselect);
  191. X                    tx->U.V40.trecord = ti;
  192. X                    tx->U.V40.tfield = tz;
  193. X                    tx = fileinit(tx, typeof(tq->U.V14.tbind), opn);
  194. X                    tx->tnext = ty;
  195. X                    ty = tx;
  196. X                    tz = tz->tnext;
  197. X                }
  198. X            }
  199. X            tq = tq->tnext;
  200. X        }
  201. X        tx = mknode(nbegin);
  202. X        tx->U.V24.tbegin = ty;
  203. X        break ;
  204. X      default:
  205. X        Caseerror(Line);
  206. X    }
  207. X    R169 = tx;
  208. X    return R169;
  209. X}
  210. X
  211. X void
  212. Xinitcode(tp)
  213. X    treeptr    tp;
  214. X{
  215. X    treeptr    ti, tq, tu, tv;
  216. X
  217. X    while (tp != (struct S61 *)NIL) {
  218. X        initcode(tp->U.V13.tsubsub);
  219. X        tv = tp->U.V13.tsubvar;
  220. X        while (tv != (struct S61 *)NIL) {
  221. X            tq = typeof(tv->U.V14.tbind);
  222. X            if (filevar(tq)) {
  223. X                ti = tv->U.V14.tidl;
  224. X                while (ti != (struct S61 *)NIL) {
  225. X                    tu = fileinit(ti, tq, true);
  226. X                    linkup(tp, tu);
  227. X                    tu->tnext = tp->U.V13.tsubstmt;
  228. X                    tp->U.V13.tsubstmt = tu;
  229. X                    while (tu->tnext != (struct S61 *)NIL)
  230. X                        tu = tu->tnext;
  231. X                    tu->tnext = fileinit(ti, tq, false);
  232. X                    linkup(tp, tu->tnext);
  233. X                    ti = ti->tnext;
  234. X                }
  235. X            }
  236. X            tv = tv->tnext;
  237. X        }
  238. X        tp = tp->tnext;
  239. X    }
  240. X}
  241. X
  242. X void
  243. Xtransform()
  244. X{
  245. X    renamc();
  246. X    renamp(top->U.V13.tsubsub, false);
  247. X    extract(top);
  248. X    renamf(top);
  249. X    initcode(top->U.V13.tsubsub);
  250. X    global(top, top, false);
  251. X}
  252. X
  253. Xvoid emit();
  254. X
  255. X void
  256. Xincrement()
  257. X{
  258. X    (*G204_indnt) = (*G204_indnt) + indstep;
  259. X}
  260. X
  261. X void
  262. Xdecrement()
  263. X{
  264. X    (*G204_indnt) = (*G204_indnt) - indstep;
  265. X}
  266. X
  267. X void
  268. Xindent()
  269. X{
  270. X    integer    i;
  271. X
  272. X    i = (*G204_indnt);
  273. X    if (i > 60)
  274. X        i = i / tabwidth * tabwidth;
  275. X    while (i >= tabwidth) {
  276. X        Putchr(tab1, output);
  277. X        i = i - tabwidth;
  278. X    }
  279. X    while (i > 0) {
  280. X        Putchr(space, output);
  281. X        i = i - 1;
  282. X    }
  283. X}
  284. X
  285. X boolean
  286. Xarithexpr(tp)
  287. X    treeptr    tp;
  288. X{
  289. X    register boolean    R170;
  290. X
  291. X    tp = typeof(tp);
  292. X    if (tp->tt == nsubrange)
  293. X        if (tp->tup->tt == nconfarr)
  294. X            tp = typeof(tp->tup->U.V22.tindtyp);
  295. X        else
  296. X            tp = typeof(tp->U.V19.tlo);
  297. X    R170 = (boolean)((tp == typnods.A[(int)(tinteger)]) || (tp == typnods.A[(int)(tchar)]) || (tp == typnods.A[(int)(treal)]));
  298. X    return R170;
  299. X}
  300. X
  301. Xvoid eexpr();
  302. X
  303. Xvoid etypedef();
  304. X
  305. X void
  306. Xeselect(tp)
  307. X    treeptr    tp;
  308. X{
  309. X    (*G202_doarrow) = (*G202_doarrow) + 1;
  310. X    eexpr(tp);
  311. X    (*G202_doarrow) = (*G202_doarrow) - 1;
  312. X    if ((*G200_donearr))
  313. X        (*G200_donearr) = false;
  314. X    else
  315. X        Putchr('.', output);
  316. X}
  317. X
  318. Xvoid epredef();
  319. X
  320. X char
  321. Xtypeletter(tp)
  322. X    treeptr    tp;
  323. X{
  324. X    register char    R171;
  325. X    treeptr    tq;
  326. X
  327. X    tq = tp;
  328. X    if (tq->tt == nformat) {
  329. X        if (tq->U.V41.texpl->tt == nformat) {
  330. X            R171 = 'f';
  331. X            goto L999;
  332. X        }
  333. X        tq = tp->U.V41.texpl;
  334. X    }
  335. X    tq = typeof(tq);
  336. X    if (tq->tt == nsubrange)
  337. X        tq = typeof(tq->U.V19.tlo);
  338. X    if (tq == typnods.A[(int)(tstring)])
  339. X        R171 = 's';
  340. X    else
  341. X        if (tq == typnods.A[(int)(tinteger)])
  342. X            R171 = 'd';
  343. X        else
  344. X            if (tq == typnods.A[(int)(tchar)])
  345. X                R171 = 'c';
  346. X            else
  347. X                if (tq == typnods.A[(int)(treal)])
  348. X                    if (tp->tt == nformat)
  349. X                        R171 = 'e';
  350. X                    else
  351. X                        R171 = 'g';
  352. X                else
  353. X                    if (tq == typnods.A[(int)(tboolean)]) {
  354. X                        R171 = 'b';
  355. X                        (*G191_nelems) = 6;
  356. X                    } else
  357. X                        if (tq->tt == narray) {
  358. X                            R171 = 'a';
  359. X                            (*G191_nelems) = crange(tq->U.V23.taindx);
  360. X                        } else
  361. X                            if (tq->tt == nconfarr) {
  362. X                                R171 = 'v';
  363. X                                (*G191_nelems) = 0;
  364. X                            } else
  365. X                                fatal(etree);
  366. XL999:
  367. X    ;
  368. X    return R171;
  369. X}
  370. X
  371. X void
  372. Xetxt(tp)
  373. X    treeptr    tp;
  374. X{
  375. X    toknbuf    w;
  376. X    char    c;
  377. X    toknidx    i;
  378. X
  379. X    switch (tp->tt) {
  380. X      case nid:
  381. X        tp = idup(tp);
  382. X        if (tp->tt == nconst)
  383. X            etxt(tp->U.V14.tbind);
  384. X        else
  385. X            fatal(etree);
  386. X        break ;
  387. X      case nstring:
  388. X        gettokn(tp->U.V43.tsym->U.V7.lstr, &w);
  389. X        i = 1;
  390. X        while (w.A[i - 1] != null) {
  391. X            c = w.A[i - 1];
  392. X            if ((c == cite) || (c == bslash))
  393. X                Putchr(bslash, output);
  394. X            else
  395. X                if (c == percent)
  396. X                    Putchr(percent, output);
  397. X            Putchr(c, output);
  398. X            i = i + 1;
  399. X        }
  400. X        break ;
  401. X      case nchar:
  402. X        c = tp->U.V43.tsym->U.V11.lchar;
  403. X        if ((c == cite) || (c == bslash))
  404. X            Putchr(bslash, output);
  405. X        else
  406. X            if (c == percent)
  407. X                Putchr(percent, output);
  408. X        Putchr(c, output);
  409. X        break ;
  410. X      default:
  411. X        Caseerror(Line);
  412. X    }
  413. X}
  414. X
  415. X void
  416. Xeformat(tq)
  417. X    treeptr    tq;
  418. X{
  419. X    treeptr    tx;
  420. X    integer    i;
  421. X
  422. X    switch (typeletter(tq)) {
  423. X      case 'a':
  424. X        Putchr(percent, output);
  425. X        if (tq->tt == nformat)
  426. X            if (tq->U.V41.texpr->tt == ninteger)
  427. X                eexpr(tq->U.V41.texpr);
  428. X            else
  429. X                Putchr('*', output);
  430. X        (void)fprintf(output.fp, ".%1ds", (*G191_nelems)), Putl(output, 0);
  431. X        break ;
  432. X      case 'b':
  433. X        Putchr(percent, output);
  434. X        if (tq->tt == nformat) {
  435. X            if (tq->U.V41.texpr->tt == ninteger)
  436. X                eexpr(tq->U.V41.texpr);
  437. X            else
  438. X                Putchr('*', output);
  439. X        }
  440. X        Putchr('s', output);
  441. X        break ;
  442. X      case 'c':
  443. X        if (tq->tt == nchar)
  444. X            etxt(tq);
  445. X        else {
  446. X            Putchr(percent, output);
  447. X            if (tq->tt == nformat)
  448. X                if (tq->U.V41.texpr->tt == ninteger)
  449. X                    eexpr(tq->U.V41.texpr);
  450. X                else
  451. X                    Putchr('*', output);
  452. X            Putchr('c', output);
  453. X        }
  454. X        break ;
  455. X      case 'd':
  456. X        Putchr(percent, output);
  457. X        if (tq->tt == nformat) {
  458. X            if (tq->U.V41.texpr->tt == ninteger)
  459. X                eexpr(tq->U.V41.texpr);
  460. X            else
  461. X                Putchr('*', output);
  462. X        } else
  463. X            (void)fprintf(output.fp, "%1d", intlen), Putl(output, 0);
  464. X        Putchr('d', output);
  465. X        break ;
  466. X      case 'e':
  467. X        (void)fprintf(output.fp, "%c%c", percent, space), Putl(output, 0);
  468. X        tx = tq->U.V41.texpr;
  469. X        if (tx->tt == ninteger) {
  470. X            i = cvalof(tx);
  471. X            (void)fprintf(output.fp, "%1d.", i), Putl(output, 0);
  472. X            i = i - 7;
  473. X            if (i < 1)
  474. X                Putchr('1', output);
  475. X            else
  476. X                (void)fprintf(output.fp, "%1d", i), Putl(output, 0);
  477. X        } else
  478. X            (void)fprintf(output.fp, "*.*"), Putl(output, 0);
  479. X        Putchr('e', output);
  480. X        break ;
  481. X      case 'f':
  482. X        Putchr(percent, output);
  483. X        tx = tq->U.V41.texpl;
  484. X        if (tx->U.V41.texpr->tt == ninteger) {
  485. X            eexpr(tx->U.V41.texpr);
  486. X            Putchr('.', output);
  487. X            tx = tq->U.V41.texpr;
  488. X            if (tx->tt == ninteger) {
  489. X                i = cvalof(tx);
  490. X                tx = tq->U.V41.texpl->U.V41.texpr;
  491. X                if (i > cvalof(tx) - 1)
  492. X                    Putchr('1', output);
  493. X                else
  494. X                    (void)fprintf(output.fp, "%1d", i), Putl(output, 0);
  495. X            } else
  496. X                Putchr('*', output);
  497. X        } else
  498. X            (void)fprintf(output.fp, "*.*"), Putl(output, 0);
  499. X        Putchr('f', output);
  500. X        break ;
  501. X      case 'g':
  502. X        (void)fprintf(output.fp, "%c%1de", percent, fixlen), Putl(output, 0);
  503. X        break ;
  504. X      case 's':
  505. X        if (tq->tt == nstring)
  506. X            etxt(tq);
  507. X        else {
  508. X            Putchr(percent, output);
  509. X            if (tq->tt == nformat)
  510. X                if (tq->U.V41.texpr->tt == ninteger)
  511. X                    eexpr(tq->U.V41.texpr);
  512. X                else
  513. X                    (void)fprintf(output.fp, "*.*"), Putl(output, 0);
  514. X            Putchr('s', output);
  515. X        }
  516. X        break ;
  517. X      default:
  518. X        Caseerror(Line);
  519. X    }
  520. X}
  521. X
  522. X void
  523. Xewrite(tq)
  524. X    treeptr    tq;
  525. X{
  526. X    treeptr    tx;
  527. X
  528. X    switch (typeletter(tq)) {
  529. X      case 'a':
  530. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  531. X        tx = tq;
  532. X        if (tq->tt == nformat) {
  533. X            if (tq->U.V41.texpr->tt != ninteger) {
  534. X                eexpr(tq->U.V41.texpr);
  535. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  536. X            }
  537. X            tx = tq->U.V41.texpl;
  538. X        }
  539. X        eexpr(tx);
  540. X        (void)fprintf(output.fp, ".A"), Putl(output, 0);
  541. X        break ;
  542. X      case 'b':
  543. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  544. X        tx = tq;
  545. X        if (tq->tt == nformat) {
  546. X            if (tq->U.V41.texpr->tt != ninteger) {
  547. X                eexpr(tq->U.V41.texpr);
  548. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  549. X            }
  550. X            tx = tq->U.V41.texpl;
  551. X        }
  552. X        usebool = true;
  553. X        (void)fprintf(output.fp, "Bools[(int)("), Putl(output, 0);
  554. X        eexpr(tx);
  555. X        (void)fprintf(output.fp, ")]"), Putl(output, 0);
  556. X        break ;
  557. X      case 'c':
  558. X        if (tq->tt == nformat) {
  559. X            if (tq->U.V41.texpr->tt != ninteger) {
  560. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  561. X                eexpr(tq->U.V41.texpr);
  562. X            }
  563. X            (void)fprintf(output.fp, ", "), Putl(output, 0);
  564. X            eexpr(tq->U.V41.texpl);
  565. X        } else
  566. X            if (tq->tt != nchar) {
  567. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  568. X                eexpr(tq);
  569. X            }
  570. X        break ;
  571. X      case 'd':
  572. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  573. X        tx = tq;
  574. X        if (tq->tt == nformat) {
  575. X            if (tq->U.V41.texpr->tt != ninteger) {
  576. X                eexpr(tq->U.V41.texpr);
  577. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  578. X            }
  579. X            tx = tq->U.V41.texpl;
  580. X        }
  581. X        eexpr(tx);
  582. X        break ;
  583. X      case 'e':
  584. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  585. X        tx = tq->U.V41.texpr;
  586. X        if (tx->tt != ninteger) {
  587. X            usemax = true;
  588. X            eexpr(tx);
  589. X            (void)fprintf(output.fp, ", Max("), Putl(output, 0);
  590. X            eexpr(tx);
  591. X            (void)fprintf(output.fp, " - 7, 1), "), Putl(output, 0);
  592. X        }
  593. X        eexpr(tq->U.V41.texpl);
  594. X        break ;
  595. X      case 'f':
  596. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  597. X        tx = tq->U.V41.texpl;
  598. X        if (tx->U.V41.texpr->tt != ninteger) {
  599. X            eexpr(tx->U.V41.texpr);
  600. X            (void)fprintf(output.fp, ", "), Putl(output, 0);
  601. X        }
  602. X        if ((tx->U.V41.texpr->tt != ninteger) || (tq->U.V41.texpr->tt != ninteger)) {
  603. X            usemax = true;
  604. X            (void)fprintf(output.fp, "Max(("), Putl(output, 0);
  605. X            eexpr(tx->U.V41.texpr);
  606. X            (void)fprintf(output.fp, ") - ("), Putl(output, 0);
  607. X            eexpr(tq->U.V41.texpr);
  608. X            (void)fprintf(output.fp, ") - 1, 1), "), Putl(output, 0);
  609. X        }
  610. X        eexpr(tq->U.V41.texpl->U.V41.texpl);
  611. X        break ;
  612. X      case 'g':
  613. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  614. X        eexpr(tq);
  615. X        break ;
  616. X      case 's':
  617. X        if (tq->tt == nformat) {
  618. X            if (tq->U.V41.texpr->tt != ninteger) {
  619. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  620. X                eexpr(tq->U.V41.texpr);
  621. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  622. X                eexpr(tq->U.V41.texpr);
  623. X            }
  624. X            (void)fprintf(output.fp, ", "), Putl(output, 0);
  625. X            eexpr(tq->U.V41.texpl);
  626. X        } else
  627. X            if (tq->tt != nstring) {
  628. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  629. X                eexpr(tq);
  630. X            }
  631. X        break ;
  632. X      default:
  633. X        Caseerror(Line);
  634. X    }
  635. X}
  636. X
  637. Xvoid enewsize();
  638. X
  639. X void
  640. Xesubsize(tp, tq)
  641. X    treeptr    tp, tq;
  642. X{
  643. X    treeptr    tx, ty;
  644. X    boolean    addsize;
  645. X
  646. X    tx = tq->U.V20.tvrnt;
  647. X    ty = tx->U.V21.tflist;
  648. X    if (ty == (struct S61 *)NIL) {
  649. X        ty = tx->U.V21.tvlist;
  650. X        while (ty != (struct S61 *)NIL) {
  651. X            if (ty->U.V20.tvrnt->U.V21.tflist != (struct S61 *)NIL) {
  652. X                ty = ty->U.V20.tvrnt->U.V21.tflist;
  653. X                goto L555;
  654. X            }
  655. X            ty = ty->tnext;
  656. X        }
  657. X    L555:
  658. X        ;
  659. X    }
  660. X    addsize = true;
  661. X    if (ty == (struct S61 *)NIL) {
  662. X        addsize = false;
  663. X        ty = tx->tup->tup->U.V21.tvlist;
  664. X        while (ty != (struct S61 *)NIL) {
  665. X            if (ty->U.V20.tvrnt->U.V21.tflist != (struct S61 *)NIL) {
  666. X                ty = ty->U.V20.tvrnt->U.V21.tflist;
  667. X                goto L666;
  668. X            }
  669. X            ty = ty->tnext;
  670. X        }
  671. X    L666:
  672. X        ;
  673. X    }
  674. X    if (ty == (struct S61 *)NIL) {
  675. X        (void)fprintf(output.fp, "sizeof(*"), Putl(output, 0);
  676. X        eexpr(tp);
  677. X        Putchr(')', output);
  678. X    } else {
  679. X        (void)fprintf(output.fp, "Unionoffs("), Putl(output, 0);
  680. X        eexpr(tp);
  681. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  682. X        printid(ty->U.V14.tidl->U.V43.tsym->U.V6.lid);
  683. X        if (addsize) {
  684. X            (void)fprintf(output.fp, ") + sizeof("), Putl(output, 0);
  685. X            eexpr(tp);
  686. X            (void)fprintf(output.fp, "->"), Putl(output, 0);
  687. X            printid(tx->U.V21.tuid);
  688. X        }
  689. X        Putchr(')', output);
  690. X    }
  691. X}
  692. X
  693. X void
  694. Xenewsize(tp)
  695. X    treeptr    tp;
  696. X{
  697. X    treeptr    tq, tx, ty;
  698. X    integer    v;
  699. X
  700. X    if ((tp->tnext != (struct S61 *)NIL) && unionnew) {
  701. X        v = cvalof(tp->tnext);
  702. X        tq = typeof(tp);
  703. X        tq = typeof(tq->U.V16.tptrid);
  704. X        if (tq->tt != nrecord)
  705. X            fatal(etree);
  706. X        tx = tq->U.V21.tvlist;
  707. X        while (tx != (struct S61 *)NIL) {
  708. X            ty = tx->U.V20.tselct;
  709. X            while (ty != (struct S61 *)NIL) {
  710. X                if (v == cvalof(ty))
  711. X                    goto L555;
  712. X                ty = ty->tnext;
  713. X            }
  714. X            tx = tx->tnext;
  715. X        }
  716. X        fatal(etag);
  717. X    L555:
  718. X        esubsize(tp, tx);
  719. X    } else {
  720. X        (void)fprintf(output.fp, "sizeof(*"), Putl(output, 0);
  721. X        eexpr(tp);
  722. X        Putchr(')', output);
  723. X    }
  724. X}
  725. X
  726. X void
  727. Xepredef(ts, tp)
  728. X    treeptr    ts, tp;
  729. X{
  730. X    treeptr    tq, tv, tx;
  731. X    predefs    td;
  732. X    integer    nelems;
  733. X    char    ch;
  734. X    boolean    txtfile;
  735. X    integer    *F192;
  736. X
  737. X    F192 = G191_nelems;
  738. X    G191_nelems = &nelems;
  739. X    td = ts->U.V13.tsubstmt->U.V12.tdef;
  740. X    switch (td) {
  741. X      case dabs:
  742. X        tq = typeof(tp->U.V30.taparm);
  743. X        if ((tq == typnods.A[(int)(tinteger)]) || (tq->tt == nsubrange))
  744. X            (void)fprintf(output.fp, "abs("), Putl(output, 0);
  745. X        else
  746. X            (void)fprintf(output.fp, "fabs("), Putl(output, 0);
  747. X        eexpr(tp->U.V30.taparm);
  748. X        Putchr(')', output);
  749. X        break ;
  750. X      case dargv:
  751. X        (void)fprintf(output.fp, "Argvgt("), Putl(output, 0);
  752. X        eexpr(tp->U.V30.taparm);
  753. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  754. X        eexpr(tp->U.V30.taparm->tnext);
  755. X        (void)fprintf(output.fp, ".A, sizeof("), Putl(output, 0);
  756. X        eexpr(tp->U.V30.taparm->tnext);
  757. X        (void)fprintf(output.fp, ".A));\n"), Putl(output, 1);
  758. X        break ;
  759. X      case dchr:
  760. X        tq = typeof(tp->U.V30.taparm);
  761. X        if (tq->tt == nsubrange)
  762. X            if (tq->tup->tt == nconfarr)
  763. X                tq = typeof(tq->tup->U.V22.tindtyp);
  764. X            else
  765. X                tq = typeof(tq->U.V19.tlo);
  766. X        if ((tq == typnods.A[(int)(tinteger)]) || (tq == typnods.A[(int)(tchar)]))
  767. X            eexpr(tp->U.V30.taparm);
  768. X        else {
  769. X            (void)fprintf(output.fp, "(char)("), Putl(output, 0);
  770. X            eexpr(tp->U.V30.taparm);
  771. X            Putchr(')', output);
  772. X        }
  773. X        break ;
  774. X      case ddispose:
  775. X        (void)fprintf(output.fp, "free("), Putl(output, 0);
  776. X        eexpr(tp->U.V30.taparm);
  777. X        (void)fprintf(output.fp, ");\n"), Putl(output, 1);
  778. X        break ;
  779. X      case deof:
  780. X        (void)fprintf(output.fp, "Eof("), Putl(output, 0);
  781. X        if (tp->U.V30.taparm == (struct S61 *)NIL) {
  782. X            defnams.A[(int)(dinput)]->U.V6.lused = true;
  783. X            printid(defnams.A[(int)(dinput)]->U.V6.lid);
  784. X        } else
  785. X            eexpr(tp->U.V30.taparm);
  786. X        Putchr(')', output);
  787. X        break ;
  788. X      case deoln:
  789. X        (void)fprintf(output.fp, "Eoln("), Putl(output, 0);
  790. X        if (tp->U.V30.taparm == (struct S61 *)NIL) {
  791. X            defnams.A[(int)(dinput)]->U.V6.lused = true;
  792. X            printid(defnams.A[(int)(dinput)]->U.V6.lid);
  793. X        } else
  794. X            eexpr(tp->U.V30.taparm);
  795. X        Putchr(')', output);
  796. X        break ;
  797. X      case dexit:
  798. X        (void)fprintf(output.fp, "exit("), Putl(output, 0);
  799. X        if (tp->U.V30.taparm == (struct S61 *)NIL)
  800. X            Putchr('0', output);
  801. X        else
  802. X            eexpr(tp->U.V30.taparm);
  803. X        (void)fprintf(output.fp, ");\n"), Putl(output, 1);
  804. X        break ;
  805. X      case dflush:
  806. X        (void)fprintf(output.fp, "fflush("), Putl(output, 0);
  807. X        if (tp->U.V30.taparm == (struct S61 *)NIL) {
  808. X            defnams.A[(int)(doutput)]->U.V6.lused = true;
  809. X            printid(defnams.A[(int)(doutput)]->U.V6.lid);
  810. X        } else
  811. X            eexpr(tp->U.V30.taparm);
  812. X        (void)fprintf(output.fp, ".fp);\n"), Putl(output, 1);
  813. X        break ;
  814. X      case dpage:
  815. X        (void)fprintf(output.fp, "Putchr(%s, ", ffchr), Putl(output, 0);
  816. X        if (tp->U.V30.taparm == (struct S61 *)NIL) {
  817. X            defnams.A[(int)(doutput)]->U.V6.lused = true;
  818. X            printid(defnams.A[(int)(doutput)]->U.V6.lid);
  819. X        } else
  820. X            eexpr(tp->U.V30.taparm);
  821. X        (void)fprintf(output.fp, ");\n"), Putl(output, 1);
  822. X        break ;
  823. X      case dput:  case dget:
  824. X        if (typeof(tp->U.V30.taparm) == typnods.A[(int)(ttext)])
  825. X            if (td == dget)
  826. X                (void)fprintf(output.fp, "Getx"), Putl(output, 0);
  827. X            else
  828. X                (void)fprintf(output.fp, "Putx"), Putl(output, 0);
  829. X        else {
  830. X            (void)fprintf(output.fp, "%s", voidcast), Putl(output, 0);
  831. X            if (td == dget)
  832. X                (void)fprintf(output.fp, "Get"), Putl(output, 0);
  833. X            else
  834. X                (void)fprintf(output.fp, "Put"), Putl(output, 0);
  835. X        }
  836. X        Putchr('(', output);
  837. X        eexpr(tp->U.V30.taparm);
  838. X        (void)fprintf(output.fp, ");\n"), Putl(output, 1);
  839. X        break ;
  840. X      case dhalt:
  841. X        (void)fprintf(output.fp, "abort();\n"), Putl(output, 1);
  842. X        break ;
  843. X      case dnew:
  844. X        eexpr(tp->U.V30.taparm);
  845. X        (void)fprintf(output.fp, " = ("), Putl(output, 0);
  846. X        etypedef(typeof(tp->U.V30.taparm));
  847. X        (void)fprintf(output.fp, ")malloc((unsigned)("), Putl(output, 0);
  848. X        enewsize(tp->U.V30.taparm);
  849. X        (void)fprintf(output.fp, "));\n"), Putl(output, 1);
  850. X        break ;
  851. X      case dord:
  852. X        (void)fprintf(output.fp, "(unsigned)("), Putl(output, 0);
  853. X        eexpr(tp->U.V30.taparm);
  854. X        Putchr(')', output);
  855. X        break ;
  856. X      case dread:  case dreadln:
  857. X        txtfile = false;
  858. X        tq = tp->U.V30.taparm;
  859. X        if (tq != (struct S61 *)NIL) {
  860. X            tv = typeof(tq);
  861. X            if (tv == typnods.A[(int)(ttext)]) {
  862. X                txtfile = true;
  863. X                tv = tq;
  864. X                tq = tq->tnext;
  865. X            } else
  866. X                if (tv->tt == nfileof) {
  867. X                    txtfile = (boolean)(typeof(tv->U.V18.tof) == typnods.A[(int)(tchar)]);
  868. X                    tv = tq;
  869. X                    tq = tq->tnext;
  870. X                } else {
  871. X                    txtfile = true;
  872. X                    tv = (struct S61 *)NIL;
  873. X                }
  874. X        } else {
  875. X            tv = (struct S61 *)NIL;
  876. X            txtfile = true;
  877. X        }
  878. X        if (txtfile) {
  879. X            if (tq == (struct S61 *)NIL)
  880. X                goto L444;
  881. X            if ((tq->tt != nformat) && (tq->tnext == (struct S61 *)NIL) && (typeletter(tq) == 'c')) {
  882. X                eexpr(tq);
  883. X                (void)fprintf(output.fp, " = "), Putl(output, 0);
  884. X                (void)fprintf(output.fp, "Getchr("), Putl(output, 0);
  885. X                if (tv == (struct S61 *)NIL)
  886. X                    printid(defnams.A[(int)(dinput)]->U.V6.lid);
  887. X                else
  888. X                    eexpr(tv);
  889. X                Putchr(')', output);
  890. X                if (td == dreadln)
  891. X                    Putchr(',', output);
  892. X                goto L444;
  893. X            }
  894. X            usescan = true;
  895. X            (void)fprintf(output.fp, "Fscan("), Putl(output, 0);
  896. X            if (tv == (struct S61 *)NIL)
  897. X                printid(defnams.A[(int)(dinput)]->U.V6.lid);
  898. X            else
  899. X                eexpr(tv);
  900. X            (void)fprintf(output.fp, "), "), Putl(output, 0);
  901. X            while (tq != (struct S61 *)NIL) {
  902. X                (void)fprintf(output.fp, "Scan(%c", cite), Putl(output, 0);
  903. X                ch = typeletter(tq);
  904. X                switch (ch) {
  905. X                  case 'a':
  906. X                    (void)fprintf(output.fp, "%cs", percent), Putl(output, 0);
  907. X                    break ;
  908. X                  case 'c':
  909. X                    (void)fprintf(output.fp, "%cc", percent), Putl(output, 0);
  910. X                    break ;
  911. X                  case 'd':
  912. X                    (void)fprintf(output.fp, "%cld", percent), Putl(output, 0);
  913. X                    break ;
  914. X                  case 'g':
  915. X                    (void)fprintf(output.fp, "%cle", percent), Putl(output, 0);
  916. X                    break ;
  917. X                  default:
  918. X                    Caseerror(Line);
  919. X                }
  920. X                (void)fprintf(output.fp, "%c, ", cite), Putl(output, 0);
  921. X                switch (ch) {
  922. X                  case 'a':
  923. X                    eexpr(tq);
  924. X                    (void)fprintf(output.fp, ".A"), Putl(output, 0);
  925. X                    break ;
  926. X                  case 'c':
  927. X                    Putchr('&', output);
  928. X                    eexpr(tq);
  929. X                    break ;
  930. X                  case 'd':
  931. X                    (void)fprintf(output.fp, "&Tmplng"), Putl(output, 0);
  932. X                    break ;
  933. X                  case 'g':
  934. X                    (void)fprintf(output.fp, "&Tmpdbl"), Putl(output, 0);
  935. X                    break ;
  936. X                  default:
  937. X                    Caseerror(Line);
  938. X                }
  939. X                Putchr(')', output);
  940. X                switch (ch) {
  941. X                  case 'd':
  942. X                    (void)fprintf(output.fp, ", "), Putl(output, 0);
  943. X                    eexpr(tq);
  944. X                    (void)fprintf(output.fp, " = Tmplng"), Putl(output, 0);
  945. X                    break ;
  946. X                  case 'g':
  947. X                    (void)fprintf(output.fp, ", "), Putl(output, 0);
  948. X                    eexpr(tq);
  949. X                    (void)fprintf(output.fp, " = Tmpdbl"), Putl(output, 0);
  950. X                    break ;
  951. X                  case 'a':  case 'c':
  952. X                    break ;
  953. X                  default:
  954. X                    Caseerror(Line);
  955. X                }
  956. X                tq = tq->tnext;
  957. X                if (tq != (struct S61 *)NIL) {
  958. X                    Putchr(',', output),Putchr('\n', output);
  959. X                    indent();
  960. X                    Putchr(tab1, output);
  961. X                }
  962. X            }
  963. X            (void)fprintf(output.fp, ", Getx("), Putl(output, 0);
  964. X            if (tv == (struct S61 *)NIL)
  965. X                printid(defnams.A[(int)(dinput)]->U.V6.lid);
  966. X            else
  967. X                eexpr(tv);
  968. X            Putchr(')', output);
  969. X            if (td == dreadln)
  970. X                Putchr(',', output);
  971. X        L444:
  972. X            if (td == dreadln) {
  973. X                usegetl = true;
  974. X                (void)fprintf(output.fp, "Getl(&"), Putl(output, 0);
  975. X                if (tv == (struct S61 *)NIL)
  976. X                    printid(defnams.A[(int)(dinput)]->U.V6.lid);
  977. X                else
  978. X                    eexpr(tv);
  979. X                Putchr(')', output);
  980. X            }
  981. X        } else {
  982. X            increment();
  983. X            while (tq != (struct S61 *)NIL) {
  984. X                (void)fprintf(output.fp, "%sFread(", voidcast), Putl(output, 0);
  985. X                eexpr(tq);
  986. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  987. X                eexpr(tv);
  988. X                (void)fprintf(output.fp, ".fp)"), Putl(output, 0);
  989. X                tq = tq->tnext;
  990. X                if (tq != (struct S61 *)NIL) {
  991. X                    Putchr(',', output),Putchr('\n', output);
  992. X                    indent();
  993. X                }
  994. X            }
  995. X            decrement();
  996. X        }
  997. X        Putchr(';', output),Putchr('\n', output);
  998. X        break ;
  999. X      case dwrite:  case dwriteln:  case dmessage:
  1000. X        txtfile = false;
  1001. X        tq = tp->U.V30.taparm;
  1002. X        if (tq != (struct S61 *)NIL) {
  1003. X            tv = typeof(tq);
  1004. X            if (tv == typnods.A[(int)(ttext)]) {
  1005. X                txtfile = true;
  1006. X                tv = tq;
  1007. X                tq = tq->tnext;
  1008. X            } else
  1009. X                if (tv->tt == nfileof) {
  1010. X                    txtfile = (boolean)(typeof(tv->U.V18.tof) == typnods.A[(int)(tchar)]);
  1011. X                    tv = tq;
  1012. X                    tq = tq->tnext;
  1013. X                } else {
  1014. X                    txtfile = true;
  1015. X                    tv = (struct S61 *)NIL;
  1016. X                }
  1017. X        } else {
  1018. X            tv = (struct S61 *)NIL;
  1019. X            txtfile = true;
  1020. X        }
  1021. X        if (txtfile) {
  1022. X            if (tq == (struct S61 *)NIL) {
  1023. X                if (Member((unsigned)(td), Conset[138])) {
  1024. X                    (void)fprintf(output.fp, "Putchr(%s, ", nlchr), Putl(output, 0);
  1025. X                    if (tv == (struct S61 *)NIL)
  1026. X                        printid(defnams.A[(int)(doutput)]->U.V6.lid);
  1027. X                    else
  1028. X                        eexpr(tv);
  1029. X                    Putchr(')', output);
  1030. X                }
  1031. X                Putchr(';', output),Putchr('\n', output);
  1032. X                goto L555;
  1033. X            } else
  1034. X                if ((tq->tt != nformat) && (tq->tnext == (struct S61 *)NIL))
  1035. X                    if (typeletter(tq) == 'c') {
  1036. X                        (void)fprintf(output.fp, "Putchr("), Putl(output, 0);
  1037. X                        eexpr(tq);
  1038. X                        (void)fprintf(output.fp, ", "), Putl(output, 0);
  1039. X                        if (tv == (struct S61 *)NIL)
  1040. X                            printid(defnams.A[(int)(doutput)]->U.V6.lid);
  1041. X                        else
  1042. X                            eexpr(tv);
  1043. X                        Putchr(')', output);
  1044. X                        if (td == dwriteln) {
  1045. X                            (void)fprintf(output.fp, ",Putchr(%s, ", nlchr), Putl(output, 0);
  1046. X                            if (tv == (struct S61 *)NIL)
  1047. X                                printid(defnams.A[(int)(doutput)]->U.V6.lid);
  1048. X                            else
  1049. X                                eexpr(tv);
  1050. X                            Putchr(')', output);
  1051. X                        }
  1052. X                        Putchr(';', output),Putchr('\n', output);
  1053. X                        goto L555;
  1054. X                    }
  1055. X            tx = (struct S61 *)NIL;
  1056. X            (void)fprintf(output.fp, "%sfprintf(", voidcast), Putl(output, 0);
  1057. X            if (td == dmessage)
  1058. X                (void)fprintf(output.fp, "stderr, "), Putl(output, 0);
  1059. X            else {
  1060. X                if (tv == (struct S61 *)NIL)
  1061. X                    printid(defnams.A[(int)(doutput)]->U.V6.lid);
  1062. X                else
  1063. X                    eexpr(tv);
  1064. X                (void)fprintf(output.fp, ".fp, "), Putl(output, 0);
  1065. X            }
  1066. X            Putchr(cite, output);
  1067. X            tx = tq;
  1068. X            while (tq != (struct S61 *)NIL) {
  1069. X                eformat(tq);
  1070. X                tq = tq->tnext;
  1071. X            }
  1072. X            if ((td == dmessage) || (td == dwriteln))
  1073. X                (void)fprintf(output.fp, "\\n"), Putl(output, 0);
  1074. X            Putchr(cite, output);
  1075. X            tq = tx;
  1076. X            while (tq != (struct S61 *)NIL) {
  1077. X                ewrite(tq);
  1078. X                tq = tq->tnext;
  1079. X            }
  1080. X            (void)fprintf(output.fp, "), Putl("), Putl(output, 0);
  1081. X            if (tv == (struct S61 *)NIL)
  1082. X                printid(defnams.A[(int)(doutput)]->U.V6.lid);
  1083. X            else
  1084. X                eexpr(tv);
  1085. X            if (td == dwrite)
  1086. X                (void)fprintf(output.fp, ", 0)"), Putl(output, 0);
  1087. X            else
  1088. X                (void)fprintf(output.fp, ", 1)"), Putl(output, 0);
  1089. X        } else {
  1090. X            increment();
  1091. X            tx = typeof(tv);
  1092. X            if (tx == typnods.A[(int)(ttext)])
  1093. X                tx = typnods.A[(int)(tchar)];
  1094. X            else
  1095. X                if (tx->tt == nfileof)
  1096. X                    tx = typeof(tx->U.V18.tof);
  1097. X                else
  1098. X                    fatal(etree);
  1099. X            while (tq != (struct S61 *)NIL) {
  1100. X                if ((Member((unsigned)(tq->tt), Conset[139])) && (tx == typeof(tq))) {
  1101. X                    (void)fprintf(output.fp, "%sFwrite(", voidcast), Putl(output, 0);
  1102. X                    eexpr(tq);
  1103. X                } else {
  1104. X                    if (tx->tt == nsetof) {
  1105. X                        usescpy = true;
  1106. X                        (void)fprintf(output.fp, "Setncpy("), Putl(output, 0);
  1107. X                        eselect(tv);
  1108. X                        (void)fprintf(output.fp, "buf.S, "), Putl(output, 0);
  1109. X                        eexpr(tq);
  1110. X                        if (typeof(tp->U.V27.trhs) == typnods.A[(int)(tset)])
  1111. X                            eexpr(tq);
  1112. X                        else {
  1113. X                            eselect(tq);
  1114. X                            Putchr('S', output);
  1115. X                        }
  1116. X                        (void)fprintf(output.fp, ", sizeof("), Putl(output, 0);
  1117. X                        eexpr(tv);
  1118. X                        (void)fprintf(output.fp, ".buf))"), Putl(output, 0);
  1119. X                    } else {
  1120. X                        eexpr(tv);
  1121. X                        (void)fprintf(output.fp, ".buf = "), Putl(output, 0);
  1122. X                        eexpr(tq);
  1123. X                    }
  1124. X                    (void)fprintf(output.fp, ", Fwrite("), Putl(output, 0);
  1125. X                    eexpr(tv);
  1126. X                    (void)fprintf(output.fp, ".buf"), Putl(output, 0);
  1127. X                }
  1128. X                (void)fprintf(output.fp, ", "), Putl(output, 0);
  1129. X                eexpr(tv);
  1130. X                (void)fprintf(output.fp, ".fp)"), Putl(output, 0);
  1131. X                tq = tq->tnext;
  1132. X                if (tq != (struct S61 *)NIL) {
  1133. X                    Putchr(',', output),Putchr('\n', output);
  1134. X                    indent();
  1135. X                }
  1136. X            }
  1137. X            decrement();
  1138. X        }
  1139. X        Putchr(';', output),Putchr('\n', output);
  1140. X    L555:
  1141. X        ;
  1142. X        break ;
  1143. X      case dclose:
  1144. X        tq = typeof(tp->U.V30.taparm);
  1145. X        txtfile = (boolean)(tq == typnods.A[(int)(ttext)]);
  1146. X        if ((!txtfile) && (tq->tt == nfileof))
  1147. X            if (typeof(tq->U.V18.tof) == typnods.A[(int)(tchar)])
  1148. X                txtfile = true;
  1149. X        if (txtfile)
  1150. X            (void)fprintf(output.fp, "Closex("), Putl(output, 0);
  1151. X        else
  1152. X            (void)fprintf(output.fp, "Close("), Putl(output, 0);
  1153. X        eexpr(tp->U.V30.taparm);
  1154. X        (void)fprintf(output.fp, ");\n"), Putl(output, 1);
  1155. X        break ;
  1156. X      case dreset:  case drewrite:
  1157. X        tq = typeof(tp->U.V30.taparm);
  1158. X        txtfile = (boolean)(tq == typnods.A[(int)(ttext)]);
  1159. X        if ((!txtfile) && (tq->tt == nfileof))
  1160. X            if (typeof(tq->U.V18.tof) == typnods.A[(int)(tchar)])
  1161. X                txtfile = true;
  1162. X        if (txtfile)
  1163. X            if (td == dreset)
  1164. X                (void)fprintf(output.fp, "Resetx("), Putl(output, 0);
  1165. X            else
  1166. X                (void)fprintf(output.fp, "Rewritex("), Putl(output, 0);
  1167. X        else
  1168. X            if (td == dreset)
  1169. X                (void)fprintf(output.fp, "Reset("), Putl(output, 0);
  1170. X            else
  1171. X                (void)fprintf(output.fp, "Rewrite("), Putl(output, 0);
  1172. X        eexpr(tp->U.V30.taparm);
  1173. X        (void)fprintf(output.fp, ", "), Putl(output, 0);
  1174. X        tq = tp->U.V30.taparm->tnext;
  1175. X        if (tq == (struct S61 *)NIL)
  1176. X            (void)fprintf(output.fp, "NULL"), Putl(output, 0);
  1177. X        else {
  1178. X            tq = typeof(tq);
  1179. X            if (tq == typnods.A[(int)(tchar)]) {
  1180. X                Putchr(cite, output);
  1181. X                ch = cvalof(tp->U.V30.taparm->tnext);
  1182. X                if ((ch == bslash) || (ch == cite))
  1183. X                    Putchr(bslash, output);
  1184. X                (void)fprintf(output.fp, "%c%c", ch, cite), Putl(output, 0);
  1185. X            } else
  1186. X                if (tq == typnods.A[(int)(tstring)])
  1187. X                    eexpr(tp->U.V30.taparm->tnext);
  1188. X                else
  1189. X                    if (Member((unsigned)(tq->tt), Conset[140])) {
  1190. X                        eexpr(tp->U.V30.taparm->tnext);
  1191. X                        (void)fprintf(output.fp, ".A"), Putl(output, 0);
  1192. X                    } else
  1193. X                        fatal(etree);
  1194. X        }
  1195. X        (void)fprintf(output.fp, ");\n"), Putl(output, 1);
  1196. X        break ;
  1197. X      case darctan:
  1198. X        (void)fprintf(output.fp, "atan("), Putl(output, 0);
  1199. X        if (typeof(tp->U.V30.taparm) != typnods.A[(int)(treal)])
  1200. X            (void)fprintf(output.fp, "%s", dblcast), Putl(output, 0);
  1201. X        eexpr(tp->U.V30.taparm);
  1202. X        Putchr(')', output);
  1203. X        break ;
  1204. X      case dln:
  1205. X        (void)fprintf(output.fp, "log("), Putl(output, 0);
  1206. X        if (typeof(tp->U.V30.taparm) != typnods.A[(int)(treal)])
  1207. X            (void)fprintf(output.fp, "%s", dblcast), Putl(output, 0);
  1208. X        eexpr(tp->U.V30.taparm);
  1209. X        Putchr(')', output);
  1210. X        break ;
  1211. X      case dexp:
  1212. X        (void)fprintf(output.fp, "exp("), Putl(output, 0);
  1213. X        if (typeof(tp->U.V30.taparm) != typnods.A[(int)(treal)])
  1214. X            (void)fprintf(output.fp, "%s", dblcast), Putl(output, 0);
  1215. X        eexpr(tp->U.V30.taparm);
  1216. X        Putchr(')', output);
  1217. X        break ;
  1218. X      case dcos:  case dsin:  case dsqrt:
  1219. X        eexpr(tp->U.V30.tcall);
  1220. X        Putchr('(', output);
  1221. X        if (typeof(tp->U.V30.taparm) != typnods.A[(int)(treal)])
  1222. X            (void)fprintf(output.fp, "%s", dblcast), Putl(output, 0);
  1223. X        eexpr(tp->U.V30.taparm);
  1224. X        Putchr(')', output);
  1225. X        break ;
  1226. X      case dtan:
  1227. X        (void)fprintf(output.fp, "atan("), Putl(output, 0);
  1228. X        if (typeof(tp->U.V30.taparm) != typnods.A[(int)(treal)])
  1229. X            (void)fprintf(output.fp, "%s", dblcast), Putl(output, 0);
  1230. X        eexpr(tp->U.V30.taparm);
  1231. X        Putchr(')', output);
  1232. X        break ;
  1233. X      case dsucc:  case dpred:
  1234. X        tq = typeof(tp->U.V30.taparm);
  1235. X        if (tq->tt == nsubrange)
  1236. X            if (tq->tup->tt == nconfarr)
  1237. X                tq = typeof(tq->tup->U.V22.tindtyp);
  1238. X            else
  1239. X                tq = typeof(tq->U.V19.tlo);
  1240. X        if ((tq == typnods.A[(int)(tinteger)]) || (tq == typnods.A[(int)(tchar)])) {
  1241. X            (void)fprintf(output.fp, "(("), Putl(output, 0);
  1242. X            eexpr(tp->U.V30.taparm);
  1243. X            if (td == dpred)
  1244. X                (void)fprintf(output.fp, ")-1)"), Putl(output, 0);
  1245. X            else
  1246. X                (void)fprintf(output.fp, ")+1)"), Putl(output, 0);
  1247. X        } else {
  1248. X            Putchr('(', output);
  1249. X            tq = tq->tup;
  1250. X            if (tq->tt == ntype) {
  1251. X                Putchr('(', output);
  1252. X                printid(tq->U.V14.tidl->U.V43.tsym->U.V6.lid);
  1253. X                Putchr(')', output);
  1254. X            }
  1255. X            (void)fprintf(output.fp, "((int)("), Putl(output, 0);
  1256. X            eexpr(tp->U.V30.taparm);
  1257. X            if (td == dpred)
  1258. X                (void)fprintf(output.fp, ")-1))"), Putl(output, 0);
  1259. X            else
  1260. X                (void)fprintf(output.fp, ")+1))"), Putl(output, 0);
  1261. X        }
  1262. X        break ;
  1263. X      case dodd:
  1264. X        Putchr('(', output);
  1265. X        printid(defnams.A[(int)(dboolean)]->U.V6.lid);
  1266. X        (void)fprintf(output.fp, ")(("), Putl(output, 0);
  1267. X        eexpr(tp->U.V30.taparm);
  1268. X        (void)fprintf(output.fp, ") & 1)"), Putl(output, 0);
  1269. X        break ;
  1270. X      case dsqr:
  1271. X        tq = typeof(tp->U.V30.taparm);
  1272. X        if ((tq == typnods.A[(int)(tinteger)]) || (tq->tt == nsubrange)) {
  1273. X            (void)fprintf(output.fp, "(("), Putl(output, 0);
  1274. X            eexpr(tp->U.V30.taparm);
  1275. X            (void)fprintf(output.fp, ") * ("), Putl(output, 0);
  1276. X            eexpr(tp->U.V30.taparm);
  1277. X            (void)fprintf(output.fp, "))"), Putl(output, 0);
  1278. X        } else {
  1279. X            (void)fprintf(output.fp, "pow("), Putl(output, 0);
  1280. X            if (typeof(tp->U.V30.taparm) != typnods.A[(int)(treal)])
  1281. X                (void)fprintf(output.fp, "%s", dblcast), Putl(output, 0);
  1282. X            eexpr(tp->U.V30.taparm);
  1283. X            (void)fprintf(output.fp, ", 2.0)"), Putl(output, 0);
  1284. X        }
  1285. X        break ;
  1286. X      case dround:
  1287. X        (void)fprintf(output.fp, "Round("), Putl(output, 0);
  1288. X        eexpr(tp->U.V30.taparm);
  1289. X        Putchr(')', output);
  1290. X        break ;
  1291. X      case dtrunc:
  1292. X        (void)fprintf(output.fp, "Trunc("), Putl(output, 0);
  1293. X        eexpr(tp->U.V30.taparm);
  1294. X        Putchr(')', output);
  1295. X        break ;
  1296. X      case dpack:
  1297. X        tq = typeof(tp->U.V30.taparm);
  1298. X        tx = typeof(tp->U.V30.taparm->tnext->tnext);
  1299. X        (void)fprintf(output.fp, "{    %s%s%c_j, _i = ", registr, inttyp, tab1), Putl(output, 0);
  1300. X        if (!arithexpr(tp->U.V30.taparm->tnext))
  1301. X            (void)fprintf(output.fp, "(int)"), Putl(output, 0);
  1302. X        eexpr(tp->U.V30.taparm->tnext);
  1303. X        if (tx->tt == narray)
  1304. X            (void)fprintf(output.fp, " - %1d", clower(tq->U.V23.taindx)), Putl(output, 0);
  1305. X        Putchr(';', output),Putchr('\n', output);
  1306. X        indent();
  1307. X        (void)fprintf(output.fp, "    for (_j = 0; _j < "), Putl(output, 0);
  1308. X        if (tq->tt == nconfarr) {
  1309. X            (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  1310. X            printid(tx->U.V22.tcindx->U.V19.thi->U.V43.tsym->U.V6.lid);
  1311. X            Putchr(')', output);
  1312. X        } else
  1313. X            (void)fprintf(output.fp, "%1d", crange(tx->U.V23.taindx)), Putl(output, 0);
  1314. X        (void)fprintf(output.fp, "; )\n"), Putl(output, 1);
  1315. X        indent();
  1316. X        Putchr(tab1, output);
  1317. X        eexpr(tp->U.V30.taparm->tnext->tnext);
  1318. X        (void)fprintf(output.fp, ".A[_j++] = "), Putl(output, 0);
  1319. X        eexpr(tp->U.V30.taparm);
  1320. X        (void)fprintf(output.fp, ".A[_i++];\n"), Putl(output, 1);
  1321. X        indent();
  1322. X        Putchr('}', output),Putchr('\n', output);
  1323. X        break ;
  1324. X      case dunpack:
  1325. X        tq = typeof(tp->U.V30.taparm);
  1326. X        tx = typeof(tp->U.V30.taparm->tnext);
  1327. X        (void)fprintf(output.fp, "{   %s%s%c_j, _i = ", registr, inttyp, tab1), Putl(output, 0);
  1328. X        if (!arithexpr(tp->U.V30.taparm->tnext->tnext))
  1329. X            (void)fprintf(output.fp, "(int)"), Putl(output, 0);
  1330. X        eexpr(tp->U.V30.taparm->tnext->tnext);
  1331. X        if (tx->tt != nconfarr)
  1332. X            (void)fprintf(output.fp, " - %1d", clower(tx->U.V23.taindx)), Putl(output, 0);
  1333. X        Putchr(';', output),Putchr('\n', output);
  1334. X        indent();
  1335. X        (void)fprintf(output.fp, "    for (_j = 0; _j < "), Putl(output, 0);
  1336. X        if (tq->tt == nconfarr) {
  1337. X            (void)fprintf(output.fp, "(int)("), Putl(output, 0);
  1338. X            printid(tq->U.V22.tcindx->U.V19.thi->U.V43.tsym->U.V6.lid);
  1339. X            Putchr(')', output);
  1340. X        } else
  1341. X            (void)fprintf(output.fp, "%1d", crange(tq->U.V23.taindx)), Putl(output, 0);
  1342. X        (void)fprintf(output.fp, "; )\n"), Putl(output, 1);
  1343. X        indent();
  1344. X        Putchr(tab1, output);
  1345. X        eexpr(tp->U.V30.taparm->tnext);
  1346. X        (void)fprintf(output.fp, ".A[_i++] = "), Putl(output, 0);
  1347. X        eexpr(tp->U.V30.taparm);
  1348. X        (void)fprintf(output.fp, ".A[_j++];\n"), Putl(output, 1);
  1349. X        indent();
  1350. X        Putchr('}', output),Putchr('\n', output);
  1351. X        break ;
  1352. X      default:
  1353. X        Caseerror(Line);
  1354. X    }
  1355. X    G191_nelems = F192;
  1356. X}
  1357. X
  1358. X void
  1359. Xeaddr(tp)
  1360. X    treeptr    tp;
  1361. X{
  1362. X    Putchr('&', output);
  1363. X    if (!(Member((unsigned)(tp->tt), Conset[141])))
  1364. X        error(evarpar);
  1365. X    eexpr(tp);
  1366. X}
  1367. X
  1368. X void
  1369. Xecall(tp)
  1370. X    treeptr    tp;
  1371. X{
  1372. X    treeptr    tf, tq, tx;
  1373. X
  1374. X    tf = idup(tp->U.V30.tcall);
  1375. X    switch (tf->tt) {
  1376. X      case nproc:  case nfunc:
  1377. X        tf = tf->U.V13.tsubpar;
  1378. X        break ;
  1379. X      case nparproc:  case nparfunc:
  1380. X        tf = tf->U.V15.tparparm;
  1381. X        break ;
  1382. X      default:
  1383. X        Caseerror(Line);
  1384. X    }
  1385. X    if (tf != (struct S61 *)NIL) {
  1386. X        switch (tf->tt) {
  1387. X          case nvalpar:  case nvarpar:
  1388. X            tf = tf->U.V14.tidl;
  1389. X            break ;
  1390. X          case nparproc:  case nparfunc:
  1391. X            tf = tf->U.V15.tparid;
  1392. X            break ;
  1393. X          default:
  1394. X            Caseerror(Line);
  1395. X        }
  1396. X    }
  1397. X    eexpr(tp->U.V30.tcall);
  1398. X    Putchr('(', output);
  1399. X    tq = tp->U.V30.taparm;
  1400. X    while (tq != (struct S61 *)NIL) {
  1401. X        if (Member((unsigned)(tf->tup->tt), Conset[142])) {
  1402. X            if (tq->tt == ncall)
  1403. X                printid(tq->U.V30.tcall->U.V43.tsym->U.V6.lid);
  1404. X            else
  1405. X                printid(tq->U.V43.tsym->U.V6.lid);
  1406. X        } else {
  1407. X            tx = typeof(tq);
  1408. X            if (tx == typnods.A[(int)(tboolean)]) {
  1409. X                tx = tq;
  1410. X                while (tx->tt == nuplus)
  1411. X                    tx = tx->U.V42.texps;
  1412. X                if (Member((unsigned)(tx->tt), Conset[143])) {
  1413. X                    Putchr('(', output);
  1414. X                    printid(defnams.A[(int)(dboolean)]->U.V6.lid);
  1415. X                    (void)fprintf(output.fp, ")("), Putl(output, 0);
  1416. X                    eexpr(tq);
  1417. X                    Putchr(')', output);
  1418. X                } else
  1419. X                    eexpr(tq);
  1420. X            } else
  1421. X                if ((tx == typnods.A[(int)(tstring)]) || (tx == typnods.A[(int)(tset)])) {
  1422. X                    (void)fprintf(output.fp, "*(("), Putl(output, 0);
  1423. X                    etypedef(tf->tup->U.V14.tbind);
  1424. X                    (void)fprintf(output.fp, " *)"), Putl(output, 0);
  1425. X                    if (tx == typnods.A[(int)(tset)]) {
  1426. X                        (*G198_dropset) = true;
  1427. X                        eexpr(tq);
  1428. X                        (*G198_dropset) = false;
  1429. X                    } else
  1430. X                        eexpr(tq);
  1431. X                    Putchr(')', output);
  1432. X                } else
  1433. X                    if (tx == typnods.A[(int)(tnil)]) {
  1434. X                        Putchr('(', output);
  1435. X                        etypedef(tf->tup->U.V14.tbind);
  1436. X                        (void)fprintf(output.fp, ")NIL"), Putl(output, 0);
  1437. X                    } else
  1438. X                        if (tf->tup->U.V14.tbind->tt == nconfarr) {
  1439. X                            (void)fprintf(output.fp, "(struct "), Putl(output, 0);
  1440. X                            printid(tf->tup->U.V14.tbind->U.V22.tcuid);
  1441. X                            (void)fprintf(output.fp, " *)&"), Putl(output, 0);
  1442. X                            eexpr(tq);
  1443. X                            if (tq->tnext == (struct S61 *)NIL)
  1444. X                                (void)fprintf(output.fp, ", %1d", crange(tx->U.V23.taindx)), Putl(output, 0);
  1445. X                        } else {
  1446. X                            if (tf->tup->tt == nvarpar)
  1447. X                                eaddr(tq);
  1448. X                            else
  1449. X                                eexpr(tq);
  1450. X                        }
  1451. X        }
  1452. X        tq = tq->tnext;
  1453. X        if (tq != (struct S61 *)NIL) {
  1454. X            (void)fprintf(output.fp, ", "), Putl(output, 0);
  1455. X            if (tf->tnext == (struct S61 *)NIL) {
  1456. X                tf = tf->tup->tnext;
  1457. X                switch (tf->tt) {
  1458. X                  case nvalpar:  case nvarpar:
  1459. X                    tf = tf->U.V14.tidl;
  1460. X                    break ;
  1461. X                  case nparproc:  case nparfunc:
  1462. X                    tf = tf->U.V15.tparid;
  1463. X                    break ;
  1464. X                  default:
  1465. X                    Caseerror(Line);
  1466. X                }
  1467. X            } else
  1468. X                tf = tf->tnext;
  1469. X        }
  1470. X    }
  1471. X    Putchr(')', output);
  1472. X}
  1473. X
  1474. Xvoid eexpr();
  1475. X
  1476. Xboolean constset();
  1477. X
  1478. X boolean
  1479. Xconstxps(tp)
  1480. X    treeptr    tp;
  1481. X{
  1482. X    register boolean    R173;
  1483. X
  1484. X    switch (tp->tt) {
  1485. X      case nrange:
  1486. X        if (constxps(tp->U.V41.texpr))
  1487. X            R173 = constxps(tp->U.V41.texpl);
  1488. X        else
  1489. X            R173 = false;
  1490. X        break ;
  1491. X      case nempty:  case ninteger:  case nchar:
  1492. X        R173 = true;
  1493. X        break ;
  1494. X      case nid:
  1495. X        tp = idup(tp);
  1496. X        R173 = (boolean)((tp->tt == nconst) || (tp->tt == nscalar));
  1497. X        break ;
  1498. X      case nin:  case neq:  case nne:  case nlt:
  1499. X      case nle:  case ngt:  case nge:  case nor:
  1500. X      case nplus:  case nminus:  case nand:  case nmul:
  1501. X      case ndiv:  case nmod:  case nquot:  case nnot:
  1502. X      case numinus:  case nuplus:  case nset:  case nindex:
  1503. X      case nselect:  case nderef:  case ncall:  case nreal:
  1504. X      case nstring:  case nnil:
  1505. X        R173 = false;
  1506. X        break ;
  1507. X      default:
  1508. X        Caseerror(Line);
  1509. X    }
  1510. X    return R173;
  1511. X}
  1512. X
  1513. X boolean
  1514. Xconstset(tp)
  1515. X    treeptr    tp;
  1516. X{
  1517. X    register boolean    R172;
  1518. X
  1519. X    R172 = true;
  1520. X    while (tp != (struct S61 *)NIL)
  1521. X        if (constxps(tp))
  1522. X            tp = tp->tnext;
  1523. X        else {
  1524. X            R172 = false;
  1525. X            tp = (struct S61 *)NIL;
  1526. X        }
  1527. X    return R172;
  1528. X}
  1529. X
  1530. END_OF_FILE
  1531. if test 37883 -ne `wc -c <'ptc.c.4'`; then
  1532.     echo shar: \"'ptc.c.4'\" unpacked with wrong size!
  1533. fi
  1534. # end of 'ptc.c.4'
  1535. fi
  1536. echo shar: End of archive 6 \(of 12\).
  1537. cp /dev/null ark6isdone
  1538. MISSING=""
  1539. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1540.     if test ! -f ark${I}isdone ; then
  1541.     MISSING="${MISSING} ${I}"
  1542.     fi
  1543. done
  1544. if test "${MISSING}" = "" ; then
  1545.     echo You have unpacked all 12 archives.
  1546.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1547. else
  1548.     echo You still need to unpack the following archives:
  1549.     echo "        " ${MISSING}
  1550. fi
  1551. ##  End of shell archive.
  1552. exit 0
  1553. -- 
  1554.  
  1555. Rich $alz            "Anger is an energy"
  1556. Cronus Project, BBN Labs    rsalz@bbn.com
  1557. Moderator, comp.sources.unix    sources@uunet.uu.net
  1558.